package com.zoffy.wmsbackend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zoffy.wmsbackend.common.BaseResponse;
import com.zoffy.wmsbackend.common.RequestParam;
import com.zoffy.wmsbackend.common.ResultUtils;
import com.zoffy.wmsbackend.model.dto.goods.GoodsDTO;
import com.zoffy.wmsbackend.model.vo.GoodsVO;
import com.zoffy.wmsbackend.service.GoodsService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
@PreAuthorize("hasAuthority('admin')")
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @PostMapping("/add")
    public BaseResponse<Boolean> addGoods(@RequestBody GoodsDTO dto){
        Boolean res = goodsService.addGoods(dto);
        return ResultUtils.success(res);
    }
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteGoods(@RequestBody GoodsDTO dto){
        Boolean res = goodsService.deleteGoods(dto);
        return ResultUtils.success(res);
    }
    @PostMapping("/update")
    public BaseResponse<Boolean> updateGoods(@RequestBody GoodsDTO dto){
        Boolean res = goodsService.updateGoods(dto);
        return ResultUtils.success(res);
    }
    @PostMapping("/list")
    public BaseResponse<IPage<GoodsVO>> listGoods(@RequestBody RequestParam<GoodsDTO> requestParam){
        IPage<GoodsVO> page = goodsService.listGoodsByPage(requestParam);
        return ResultUtils.success(page);
    }
}
